<?php

function model_users($bdd) {

    $results = $bdd->query('SELECT * FROM `users`');

    return $results;
}

function count_users($bdd) {
    $req = $bdd->query('SELECT id_user FROM users');
    $count = $req->rowCount();
    return $count;
}
function select_type($bdd,$id)
{ $result = $bdd->query("SELECT img_type FROM users WHERE id_user='$id'");
    
    return $result;
}

function model_update_users($bdd, $user_job, $user_email, $user_name, $user_surname, $user_login, $user_id, $type_img, $user_description) {
// premier enregistrement
    if ($type_img != 3) {
        $bdd->query("UPDATE users
            SET    user_job      = '$user_job',
	       user_email = '$user_email',
              user_name     = '$user_name',
	        user_surname      = '$user_surname',
	        user_login      = '$user_login',
                        img_type = '$type_img',
                        user_description   ='$user_description'
           WHERE id_user = '$user_id' ");
    } else {
        $bdd->query("UPDATE users
            SET  user_job      = '$user_job',
	       user_email = '$user_email',
              user_name     = '$user_name',
	        user_surname      = '$user_surname',
	        user_login      = '$user_login',
             user_description   ='$user_description'
           WHERE id_user = '$user_id' ");
    }
}

function model_update_Allusers($bdd, $i, $user_job, $user_email, $user_name, $user_surname, $user_login, $type_img, $user_description) {
    if ($type_img != 3) {
        $bdd->query("UPDATE users
            SET  user_job      = '$user_job',
	       user_email = '$user_email',
              user_name     = '$user_name',
	        user_surname      = '$user_surname',
               user_description   ='$user_description',
	        user_login      = '$user_login',
                    img_type = '$type_img'
           WHERE id_user = '$i' ");
    } else {
        $bdd->query("UPDATE users
            SET user_job      = '$user_job',
	       user_email = '$user_email',
              user_name     = '$user_name',
	        user_surname      = '$user_surname',
	        user_login      = '$user_login',
               user_description   ='$user_description'
           WHERE id_user = '$i' ");
    }
}

function delete_user($bdd, $user_id) {
    $bdd->query("DELETE 
            FROM users  
	    WHERE id_user = '$user_id'");
}

?>
